package com.example.sample.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.sample.R;

import java.util.ArrayList;
import java.util.List;

public class MemJitterActivity extends Activity {

    private static final String TAG = MemJitterActivity.class.getSimpleName();
    private List<String> strings = new ArrayList<>();

    private TextView tv_counter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mem_jittery);
        tv_counter = findViewById(R.id.tv_counter);
        findViewById(R.id.btn_alloc_mem).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < 10000; i++){
                    String a = new String("sdfffsakdjfjlasjdfl;asjldfkjsadl;fkj;asdjfl;asjfdlasf");
                    strings.add(a);
                }
            }
        });

        Log.i(TAG, "" + "gdejicbegh".hashCode());
        Log.i(TAG, "" + "hgebcijedg".hashCode());

        schedule();
        Debug.startMethodTracing("app");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Debug.stopMethodTracing();
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

    private void schedule(){
        handler.postDelayed(runnable, 1000);
    }

    private Handler handler = new Handler(Looper.getMainLooper());

    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            System.out.println(""+counter);
            tv_counter.setText(""+counter);
            counter++;
            schedule();
        }
    };

    private int counter = 1;
}
